//
//  ICMLevelView.m
//  ICrEAM
//
//  Created by xphone on 16/11/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMLevelView.h"

@implementation ICMLevelView

- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        self.bigScrollView = [[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
//        self.bigScrollView.backgroundColor = [UIColor clearColor];
        [self addSubview:self.bigScrollView];
        [self.bigScrollView addSubview:self.titlelabel];
        [self.bigScrollView addSubview:self.nameTextField];
        [self.bigScrollView addSubview:self.psTextField];
        [self.bigScrollView addSubview:self.commitBtn];
        [self.bigScrollView addSubview:self.cancelBtn];
        
        self.backgroundColor = BackgroundColor_White;
        CornerRadius(self, RadiusValue);
        BorderColor(self, BorderColor_Gray_Hex);
        BorderWidth(self, 1);
    }
    
    
    return self;
}

- (UILabel *)titlelabel
{
    if(!_titlelabel)
    {
        _titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, self.frame.size.width, 30)];
    }
    _titlelabel.text = self.isBalance?@"总部积分使用授权请联系关爱总监":@"授权";
    _titlelabel.font = NaviFont;
    _titlelabel.textColor = TitleColor_Dark;
    _titlelabel.textAlignment = NSTextAlignmentCenter;
    return _titlelabel;
}

- (ICMTitleTextFeildView *)nameTextField
{
    if(!_nameTextField)
    {
        _nameTextField = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(15, 60, 200, 90) title:@"登录名"];
        _nameTextField.centerX = self.width/2.0;
    }
    return _nameTextField;
}

- (ICMTitleTextFeildView *)psTextField
{
    if(!_psTextField)
    {
        _psTextField = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(15, self.nameTextField.bottomEdge, 200, 90) title:@"密码"];
        _psTextField.centerX = self.width/2.0;
    }
    return _psTextField;
}

- (UIButton *)commitBtn
{
    if(!_commitBtn)
    {
        _commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.psTextField.x, self.psTextField.bottomEdge+10, 80, 40)];
    }
    [_commitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [_commitBtn setBackgroundColor:TitleColor];
    [_commitBtn setTitleColor:BackgroundColor_White forState:UIControlStateNormal];
    [_commitBtn addTarget:self action:@selector(commit) forControlEvents:UIControlEventTouchUpInside];
    CornerRadius(_commitBtn, RadiusValue);
    return _commitBtn;
}

- (UIButton *)cancelBtn
{
    if(!_cancelBtn)
    {
        _cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.psTextField.rightEdge-80, self.psTextField.bottomEdge+10, 80, 40)];
    }
    [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [_cancelBtn setBackgroundColor:TitleColor];
    [_cancelBtn setTitleColor:BackgroundColor_White forState:UIControlStateNormal];
    [_cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    CornerRadius(_cancelBtn, RadiusValue);
    return _cancelBtn;
}

- (void)commit
{
    if([self.delegate respondsToSelector:@selector(levelCommitWithName:WithPs:)])
    {
        [self.delegate levelCommitWithName:self.nameTextField.contentText WithPs:self.psTextField.contentText];
    }
}

- (void)cancel
{
    if([self.delegate respondsToSelector:@selector(levelCancel)])
    {
        [self.delegate levelCancel];
    }
}

@end
